<script setup name="name">
import { ref, reactive, defineEmits } from 'vue'
import { GetSupplierListAPI } from '@/api/material/common'
const emit = defineEmits(['selectsubmit', 'preservation', 'cancel', 'reset'])
const props = defineProps({
  isShow: {
    type: Boolean,
    default: false
  }
})
const loading = ref(false)

// 查询条件
const query = reactive({
  pageNum: 1,
  pageSize: 10,
  spareinfoName: '' // 备件名称
})

const handleSelect = ref({ id: '' })
const TableData = ref([
  { id: 1, a: 'DB123', b: '名称', c: '规格', d: '基建' },
  {
    id: 2,
    a: '111',
    b: '111',
    c: '111',
    d: '111'
  },
  {
    id: 3,
    a: '222',
    b: '222',
    c: '222',
    d: '222'
  }
])
const total = ref(0)

// 勾选数据
const handleSelectionChange = row => {
  // console.log(row)
  handleSelect.value = row
}
// 是否禁用保存
const d = computed(() => {
  return handleSelect.value?.id ? false : true
})

// 提交查询
const Submit = () => {
  emit('selectsubmit', handleSelect.value)
}

// 提交
const preservation = () => {
  emit('preservation', handleSelect.value)
}

// 重置
const reset = () => {
  query.supplierName = ''
  //   getList()
}

// 查询
// const getList = async () => {
//   handleSelect.value.id = 0
//   loading.value = true
//   const res = await GetSupplierListAPI(query)
//   if (res.code !== 200) return
//   total.value = res.total
//   TableData.value = res.rows
//   loading.value = false
// }
// getList()
</script>
<template>
  <div class="app-container">
    <p-XiaoheDialog :dialogVisible="props.isShow" title="备件信息" @close="emit('cancel')" width="50%">
      <template #body>
        <!-- 查询条件 -->
        <el-form :inline="true" label-width="100px">
          <el-form-item label="备件编码">
            <el-select v-model="value" class="m-2" placeholder="请选择">
              <el-option v-for="item in []" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="备件名称">
            <el-input clearable v-model.trim="query.supplierName" placeholder="输入客户名称" />
          </el-form-item>
        </el-form>
        <el-divider />
        <el-table
          stripe
          border
          v-if="!loading"
          v-loading="loading"
          :data="TableData"
          highlight-current-row
          @current-change="handleSelectionChange"
        >
          <el-table-column width="80">
            <template #default="scope">
              <el-radio-group v-model="handleSelect.id">
                <el-radio :label="scope.row.id" size="large">&nbsp;</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column label="序号" width="80" type="index" />
          <el-table-column label="备件编码" prop="a" width="auto" />
          <el-table-column label="备件名称" prop="b" width="auto" />
          <el-table-column label="备件规格" prop="c" width="auto" />
          <el-table-column label="备件类别" prop="d" width="auto" />
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="query.pageNum"
          v-model:limit="query.pageSize"
          @pagination="getList"
        />
        <!-- 按钮 -->
        <div>
          <el-row class="Btn">
            <el-button type="primary" @click="getList">查询列表</el-button>
            <el-button type="info" @click="reset">重置</el-button>
            <el-button type="success" @click="preservation" :disabled="d">保存</el-button>
            <el-button type="info" @click="emit('cancel')">取消</el-button>
          </el-row>
        </div>
      </template>
    </p-XiaoheDialog>
  </div>
</template>

<style scoped lang="scss">
.Btn {
  margin-top: 10px;
  float: right;
}
</style>
